class Solution {
public:
    int maximumPrimeDifference(vector<int>& nums)
    {
        int ans = 0;
        int first = -1;
        for (int j = 0; j < nums.size(); j++)
        {
            bool flag = true;
            if (nums[j] == 1) continue;
            for (int i = 2; i <= nums[j] / i; i++)
            {
                if (nums[j] % i == 0)
                {
                    flag = false;
                    break;
                }
            }
            if (flag && first == -1) first = j;
            else if (flag && first != -1) ans = j - first;
        }
        return ans;
    }
};